package top.chendawei.aop.bus;

import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.chendawei.system.beans.entity.OperationLog;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Slf4j
@Component
public class GuavaBus {
    @Autowired
    private GuavaLogEvent guavaLogEvent;

    public static final EventBus bus = new EventBus();

    public static void register(GuavaLogEvent event) {
        if (event == null)
            return;
        bus.register(event);
    }

    public static void post(OperationLog info) {
        bus.post(info);
    }

    @PostConstruct
    public void init() {
        log.info("init...............................");
        register(guavaLogEvent);
    }

    @PreDestroy
    public void destroy() {
        log.info("destroy.............................");
    }

}
